//
//  MemberAddressCell.m
//  HAODE
//
//  Created by panquanReabam.com on 15/12/15.
//  Copyright © 2015年 reabam.com. All rights reserved.
//

#import "MemberAddressCell.h"
@interface MemberAddressCell()

@property (strong, nonatomic)  UILabel *lineLabel;
@property (strong, nonatomic)  UILabel *name;
@property (strong, nonatomic)  UILabel *phone;
@property (strong, nonatomic)  UILabel *address;
@property (strong, nonatomic)  UIButton *editBtn;
@property (strong, nonatomic)  UIButton *deleteBtn;
@property (strong, nonatomic)  UIButton *theDefaultBtn;
@property (strong, nonatomic)  UILabel *theDefaultLabel;


@end
@implementation MemberAddressCell

{
  

}
@synthesize mDelegate;

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        //self.backgroundColor = [UIColor colorWithRed:231/255.0 green:231/255.0 blue:231/255.0 alpha:1];

        [self createView];
        [self setViewAutoLayout];
    }
    
    return self;
    
}
-(void)createView
{
   
    self.name=[[UILabel alloc] init];
    self.name.font= [UIFont systemFontOfSize:17];
    self.name.textColor=[UIColor colorWithRed:51/255.0f green:51/255.0f blue:51/255.0f alpha:1.0];
    [self addSubview:self.name];

    
    self.phone=[[UILabel alloc] init];
    self.phone.font= [UIFont systemFontOfSize:17];
    self.phone.textColor=[UIColor colorWithRed:51/255.0f green:51/255.0f blue:51/255.0f alpha:1.0];
    [self addSubview:self.phone];
    
    self.address=[[UILabel alloc] init];
    self.address.font= [UIFont systemFontOfSize:14];
    self.address.textColor=zhonghuiColor;
    [self addSubview:self.address];
 
    self.theDefaultBtn=[[UIButton alloc] init];
    self.theDefaultBtn.tag=self.index.intValue;
    [self.theDefaultBtn setBackgroundImage:[UIImage imageNamed:@"sheweimoren_normal"] forState:UIControlStateNormal];
    [self addSubview:self.theDefaultBtn];
    
    self.theDefaultLabel=[[UILabel alloc] init];
    self.theDefaultLabel.text=@"默认设置";
    self.theDefaultLabel.font= [UIFont systemFontOfSize:14];
    self.theDefaultLabel.textColor=shenhuiColor;
    [self addSubview:self.theDefaultLabel];
    
    
    self.deleteBtn=[[UIButton alloc] init];
    self.deleteBtn.titleLabel.font= [UIFont systemFontOfSize:14];
    [self.deleteBtn setTitle:@"删除" forState:UIControlStateNormal];
    self.deleteBtn.tag=self.index.intValue;
    [self.deleteBtn setTitleColor:zhonghuiColor forState:UIControlStateNormal];
    [self addSubview:self.deleteBtn];
    
    
    self.editBtn=[[UIButton alloc] init];
    self.editBtn.titleLabel.font= [UIFont systemFontOfSize:14];
    [self.editBtn setTitle:@"编辑" forState:UIControlStateNormal];
    self.editBtn.tag=self.index.intValue;
    [self.editBtn setTitleColor:zhonghuiColor forState:UIControlStateNormal];
    [self addSubview:self.editBtn];

   UIImageView *_xianview = [[UIImageView alloc]initWithFrame:CGRectMake(15,97-0.5, ScreenWidth-30, 0.5)];
    _xianview.image=[UIImage imageNamed:@"hengxian"];
    
    [self addSubview:_xianview];
    
    
    self.lineLabel=[[UILabel alloc] initWithFrame:CGRectMake(0,140, ScreenWidth, 10)];
    [self.lineLabel setBackgroundColor:[UIColor colorWithRed:238.0f/255.0f green:238.0f/255.0f blue:238.0f/255.0f alpha:1.0f]];
    self.lineLabel.textColor=[UIColor clearColor];
    [self addSubview:self.lineLabel];
    
}
-(void)setModel:(MemberAddressModel *)model
{
    
    [self createView];
    [self setViewAutoLayout];

    
   
    if ([model.isDefault intValue]==1) {
        
        [self.theDefaultBtn setBackgroundImage:[UIImage imageNamed:@"jizhumima_hight"] forState:UIControlStateNormal];
        
        
    }
   
    [self.theDefaultBtn addTarget:self action:@selector(theDefaultBtn:) forControlEvents:UIControlEventTouchUpInside];
    [self.deleteBtn addTarget:self action:@selector(deleteBtn:) forControlEvents:UIControlEventTouchUpInside];
    [self.editBtn addTarget:self action:@selector(edit:) forControlEvents:UIControlEventTouchUpInside];
    self.name.text=[NSString stringWithFormat:@"%@   %@",  model.name ,model.phone ];
    self.lineLabel.text=[NSString stringWithFormat:@"%@",model.name];
    self.phone.text=[NSString stringWithFormat:@"%@",model.phone];
    self.address.text=[NSString stringWithFormat:@"%@%@%@%@",model.provinceName,model.cityName,model.regionName,model.address];
    
}
-(void)deleteBtn:(UIButton*)sender{
    
  
  [mDelegate deleteBtn:[NSString stringWithFormat:@"%ld"
                         ,sender.tag]];

}
-(void)edit:(UIButton*)sender{
    
    
    [mDelegate edit:[NSString stringWithFormat:@"%ld"
                     ,sender.tag]];

    
}
-(void)theDefaultBtn:(UIButton*)sender{
    
  
    [mDelegate theDefaultBtn:[NSString stringWithFormat:@"%ld"
                              ,sender.tag]];
    
    
}


-(void)setViewAutoLayout
{
    [self.name mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left).with.offset(15) ;
        make.height.equalTo(@16);
        make.top.equalTo(self.mas_top).with.offset(25);
    }];
    
       [self.address mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(self.mas_left).with.offset(15);
        make.right.equalTo(self.mas_right).with.offset(15);
        make.height.equalTo(@14);
        make.top.equalTo(self.name.mas_bottom).with.offset(15);
       
    }];
    
    [self.theDefaultBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left).with.offset(15) ;
        make.width.equalTo(@20);
        make.height.equalTo(@20);
        
        make.top.equalTo(self.mas_top).with.offset(100);
        
    }];
    
    
    [self.theDefaultLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(self.theDefaultBtn.mas_right).with.offset(5);
        make.height.equalTo(@14);
        make.centerY.equalTo(self.theDefaultBtn.mas_centerY) ;
    }];
   
    
    [self.deleteBtn mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.equalTo(self.mas_left).with.offset(10);
        make.right.equalTo(self.mas_right).with.offset(-15);
        
//        make.right.equalTo(self.mas_right).with.offset(15);
        make.height.equalTo(@14);
        
        make.centerY.equalTo(self.theDefaultBtn.mas_centerY) ;
        
    }];
       [self.editBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.right.equalTo(self.deleteBtn.mas_left).with.offset(-15);
        
        make.height.equalTo(@14);
        
        make.centerY.equalTo(self.theDefaultBtn.mas_centerY) ;
    }];
   

        
    
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}

@end
